/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.butnet.myframe.template.impl;

import java.io.File;
import java.io.InputStream;

import com.butnet.myframe.template.Template;
import com.butnet.myframe.template.TemplateLexer;
import com.butnet.myframe.template.TemplateLexerListener;
import com.butnet.myframe.template.TemplateNodeFactory;
import com.butnet.myframe.template.TemplateReader;

/**
 * 
 * @author Administrator
 */
public class TemplateReaderImpl implements TemplateReader {
	private TemplateLexer lexer = null;
	private TemplateNodeFactory factory = null;
	private TemplateLexerListener listener = null;

	public TemplateReaderImpl(TemplateLexer lexer) {
		this.lexer = lexer;
		TemplateNodeFacotryImpl templateNodeFacotryImpl = new TemplateNodeFacotryImpl();
		this.factory = templateNodeFacotryImpl;
		this.listener = templateNodeFacotryImpl;
	}

	@Override
	public Template read(InputStream in) {
		Template t = new TemplateImpl();

		lexer.addTemplateLexerListener(listener);
		lexer.parse(in);

		factory.parse(t);

		return t;
	}

	@Override
	public Template read(File file) {
		Template t = new TemplateImpl();

		lexer.addTemplateLexerListener(listener);
		lexer.parse(file);

		factory.parse(t);

		return t;
	}
}
